package com.ruoyi.lxs.common.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import java.util.Date;

/**
 * @author LiXingShuai
 * @className JwtTokenUtils
 * @description: TODO
 * @date 2023年06月01日
 * @version: 1.0
 */
public class JwtTokenUtils {


    private  static String SECRET_KEY = "123123123";

    private static  long EXPIRATION_TIME = 5 *60*1000L;

    public static String createJwtToken(String username) {
        return Jwts.builder()
                .setSubject(username)
                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME))
                .signWith(SignatureAlgorithm.HS256, SECRET_KEY)
                .compact();
    }


    public static boolean verifyJwtToken(String token) {
        try {
            Jws<Claims> claimsJws = Jwts.parser()
                    .setSigningKey(SECRET_KEY)
                    .parseClaimsJws(token);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
